package com.yc.demo.servlet.login;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/reg.s")
public class RegServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		// 判断用户名和密码是否填写
		response.setContentType("text/html;charset=utf-8");
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		
		if(name==null || name.trim().isEmpty()) {
			// json
			String json = "{ \"code\" : \"0\", \"msg\" : \"用户名不能为空\"}";
			response.getWriter().append(json);
		} else if(pwd==null || pwd.trim().isEmpty()) {
			// json
			String json = "{ \"code\" : \"0\", \"msg\" : \"密码不能为空\"}";
			response.getWriter().append(json);
		} else {
			String json = "{ \"code\" : \"1\", \"msg\" : \"用户注册成功！\"}";
			response.getWriter().append(json);
		}

	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doGet(request, response);
	}

}
